﻿@page "/datagrid-frozen-columns"

@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inject NorthwindContext dbContext

<h1>DataGrid <strong>Frozen Columns</strong></h1>

<p>Lock columns to prevent them from scrolling out of view via the <code>Frozen</code> property.</p>

<RadzenExample Name="DataGridFrozenColumns" Heading="false">
    <RadzenDataGrid AllowFiltering="true" AllowColumnResize="true" FilterMode="FilterMode.Advanced" AllowPaging="true" AllowSorting="true" Data="@employees" TItem="Employee" 
        ColumnWidth="300px" LogicalFilterOperator="LogicalFilterOperator.Or" Style="height:300px">
        <Columns>
            <RadzenDataGridColumn TItem="Employee" Property="EmployeeID" Filterable="false" Title="ID" Frozen="true" Width="50px" TextAlign="TextAlign.Center" />
            <RadzenDataGridColumn TItem="Employee" Title="Photo" Sortable="false" Filterable="false" Width="200px" Frozen="@frozen">
                <HeaderTemplate>
                    <RadzenCheckBox @bind-Value="frozen" title="Pin/Unpin this column" />
                </HeaderTemplate>
                <Template Context="data">
                    <RadzenImage Path="@data.Photo" style="width: 40px; height: 40px; border-radius: 8px;" />
                </Template>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="Employee" Property="FirstName" Title="First Name" Frozen="true">
                <FooterTemplate>
                    Total employees: <b>@employees.Count()</b>
                </FooterTemplate>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="Employee" Property="LastName" Title="Last Name" Width="150px">
                 <FooterTemplate>
                    Footer
                </FooterTemplate>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="Employee" Property="Title" Title="Title" />
            <RadzenDataGridColumn TItem="Employee" Property="TitleOfCourtesy" Title="Title Of Courtesy" />
            <RadzenDataGridColumn TItem="Employee" Property="BirthDate" Title="Birth Date" FormatString="{0:d}" />
            <RadzenDataGridColumn TItem="Employee" Property="HireDate" Title="Hire Date" FormatString="{0:d}" />
            <RadzenDataGridColumn TItem="Employee" Property="Address" Title="Address" />
            <RadzenDataGridColumn TItem="Employee" Property="City" Title="City" />
            <RadzenDataGridColumn TItem="Employee" Property="Region" Title="Region" />
            <RadzenDataGridColumn TItem="Employee" Property="PostalCode" Title="Postal Code" />
            <RadzenDataGridColumn TItem="Employee" Property="Country" Title="Country" />
            <RadzenDataGridColumn TItem="Employee" Property="HomePhone" Title="Home Phone" />
            <RadzenDataGridColumn TItem="Employee" Property="Extension" Title="Extension" />
            <RadzenDataGridColumn TItem="Employee" Property="Notes" Title="Notes" />
        </Columns>
    </RadzenDataGrid>
</RadzenExample>
@code {
    IEnumerable<Employee> employees;
    bool frozen;

    protected override void OnInitialized()
    {
        employees = dbContext.Employees;
    }
}